﻿using Quartz;
using Quartz.Spi;

namespace quartz_service.JobModels
{
    public class QuartzJobFactory(IServiceProvider serviceProvider) : IJobFactory
    {
        private readonly IServiceProvider serviceProvider = serviceProvider;

        public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
        {
            if (serviceProvider.GetRequiredService(bundle.JobDetail.JobType) is IJob job)
            {
                return job;
            }

            throw new Exception("服务未注册");
        }

        public void ReturnJob(IJob job) { }
    }
}
